package com.fingard.dsp.bank.directbank.jyrb01;

import com.fingard.dsp.bank.directbank.DirectBase;
import com.fingard.net.ITcpClient;
import com.fingard.net.TcpReceiver;
import com.fingard.net.WebRequest;
import com.fingard.text.StringHelper;
import com.fingard.xml.XmlTextWriter;

/**
 * Created by F on 2018/4/24.
 */
public class JYRB01Base extends DirectBase{

    protected String getCharset() {
        return "GBK";
    }

    protected void wirteCommenHeader(XmlTextWriter xmlTextWriter, JYRB01Header header) {
        xmlTextWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"GB2312\"?>");
        xmlTextWriter.writeStartElement("Message");
        xmlTextWriter.writeStartElement("Head");
        xmlTextWriter.writeElementString("TrsCode", header.trsCode);
        xmlTextWriter.writeElementString("ERPTrsTimestamp", header.ERPTrsTimestamp);
        if (StringHelper.hasAnyChar(header.ERPJnlNo)) {
            xmlTextWriter.writeElementString("ERPJnlNo", header.ERPJnlNo);
        }
        xmlTextWriter.writeEndElement();
    }

    protected String[] sendToBank(String p_reqStr,String p_for) throws Exception {
        String[] result = {"", ""};
        WriteBankLogStep2(p_reqStr);
        WebRequest webRequest = new WebRequest(bankFront.getUrl(p_for));
        result = webRequest.upload(p_reqStr.getBytes(getCharset()), getCharset());
        WriteBankLogStep3(result[1]);
        return result;
    }
}
